<template>
    <div>
        <p>Search For GitHub</p>
        <input type="text" placeholder="please input your keywords" v-model="keywords">
        <button @click="searchUsers">Search</button>
    </div>
</template>

<script>
import axios from "axios"
export default {
    name:'Search',
    data() {
        return {
            keywords:''
        }
    },
    methods:{
        searchUsers(){
            this.$bus.$emit('getData',{isFirst:false,isLoading:true,errMsg:'',users:[]})
            axios.get(`https://api.github.com/search/users?q=${this.keywords}`).then(
                response=>{
                    this.$bus.$emit('getData',{isLoading:false,errMsg:'',users:response.data.items})
                },
                error =>{
                    this.$bus.$emit('getData',{isLoading:false,errMsg:error.message,users:[]})
                }
            )
        }
    }
}
</script>

<style>

</style>